package com.wjy.sfhcore.ui.fragment.list;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.wjy.sfhcore.R;
import com.wjy.sfhcore.ui.third_party.refresh.PullToRefreshStickyListView;
import com.wjy.sfhcore.ui.third_party.refresh.base.PullToRefreshBase;
import com.wjy.sfhcore.ui.third_party.stickylistheaders.StickyListHeadersListView;
import com.wjy.sfhcore.util.Tools;


/**
 * 此类用来替代 ListActivity, 用于2.x系统的兼容
 *
 * @author b456
 */
public abstract class BaseStickyListFragment<D, L> extends
        BaseAdapterViewFragment<D, L, StickyListHeadersListView> {
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.lib_sticky_list_content_simple,
                container, false);
        return view;
    }

    protected boolean isNeedDriverLine() {
        return true;
    }

    protected void initAdapterView(View view) {
        mAdapterViewBase = (PullToRefreshStickyListView) view
                .findViewById(R.id.list);
        mAdapterView = mAdapterViewBase.getRefreshableView();
        View childView = initHeaderChildView();
        if (childView != null) {
            mAdapterView.addHeaderView(childView);
        }
        mAdapterView.setOnItemClickListener(this);
        mAdapterView.setOnItemLongClickListener(this);
        mAdapterViewBase.getLoadingLayoutProxy().setLastUpdatedLabel(
                Tools.isEmpty(lastRefreshDate) ? ""
                        : getString(R.string.xlistview_header_last_time)
                        + Tools.trim(lastRefreshDate));
        if (!isNeedDriverLine()) {
            mAdapterView.setDivider(null);
        }
    }

    protected void setAdapter() {
        mAdapterView.setAdapter(mAdapter);
    }

    protected void setLoadingMore(boolean isHasMore) {
        if (isHasMore) {
            mAdapterViewBase.setMode(PullToRefreshBase.Mode.BOTH);
        } else {
            mAdapterViewBase.setMode(PullToRefreshBase.Mode.PULL_FROM_START);
        }
    }

    public void onLastItemVisible() {
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

}